home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / lzw4c13.zip / UN_ARC.C < prev    next >
Text File  |  1993-08-29  |  2KB  |  90 lines

  1. /*
  2. **   UN_ARC.C       Copyright (C) 1992 by MarshallSoft Computing, Inc.
  3. **
  4. **   This program is used to expand archive created with MK_ARC. For
  5. **   example, to un-archive all the files in 'C.ARF', type:
  6. **
  7. **      UN_ARC C.ARF
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <dos.h>
  13. #include <fcntl.h>
  14. #include <sys\types.h>
  15. #include <sys\stat.h>
  16. #include <io.h>
  17.  
  18. #include "LZW4C.H"
  19. #include "RW_IO.H"
  20. #include "DIR_IO.H"
  21.  
  22. void SayError(int);
  23.  
  24. void main(argc,argv)
  25. int argc;
  26. char *argv[];
  27. {int i, k, c;
  28.  int RetCode;
  29.  char Filename[15];
  30.  int Files = 0;
  31.  /* begin */
  32.  if(argc!=2)
  33.    {printf("Usage: UN_ARC <archive_filespec>\n");
  34.     exit(1);
  35.    }
  36.  RetCode = InitLZW(malloc,14);
  37.  if(RetCode<0)
  38.    {SayError(RetCode);
  39.     exit(2);
  40.    }
  41.  puts("\nUN_ARC 1.0: Type any key to abort...");
  42.  /* open input file for expansion */
  43.  if(!ReaderOpen(argv[1])) exit(4);
  44.  for(i=0;;i++)
  45.    {if(kbhit())
  46.       {puts("\n...Aborted by user !");
  47.        break;
  48.       }
  49.     /* get filename */
  50.     for(k=0;k<5;k++)
  51.        {c = Reader();
  52.         if(c==-1)
  53.            {ReaderClose();
  54.             TermLZW(free);
  55.             printf("\n%d files expanded\n",Files);
  56.             exit(0);
  57.            }
  58.         /* skip past any 0's */
  59.         if(c!='\0') break;
  60.        }
  61.     Filename[0] = (char)c;
  62.     for(k=1;k<13;k++)
  63.        {c = Reader();
  64.         Filename[k] = (char)c;
  65.         if(c=='\0') break;
  66.        }
  67.     if(c!='\0')
  68.        {printf("ERROR: Cannot find filename in %s\n",argv[1]);
  69.         TermLZW(free);
  70.         exit(0);
  71.        }
  72.     if(strcmp(Filename,argv[1])==0)
  73.       {printf("ERROR: Archive contains file '%s' named same as archive\n",argv[1]);
  74.        exit(1);
  75.       }
  76.     else
  77.       {/* open output file */
  78.        printf("Expanding %12s ",Filename);
  79.        if(!WriterOpen(Filename)) exit(3);
  80.        /* do the expansion */
  81.        Files++;
  82.        if((RetCode=Expand(Reader,Writer))<0)
  83.          {SayError(RetCode);
  84.           exit(5);
  85.          }
  86.        puts("OK");
  87.        WriterClose();
  88.       }
  89.    }
  90. }